<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.w3.org/1999/xhtml">

<head>
    <th:block th:include="common/common_head :: commonHeader('角色管理')"/>
</head>

<body class="gray-bg">

<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-condition">
            <form id="roleForm" class="form-inline" th:action="@{/sys/role/list}">
                <div class="select-list">
                    <ul>
                        <li>
                            角色名称：<input type="text" id="roleName" name="roleName"/>
                        </li>
                        <li>
                            <button id="roleSearchBtn" type="button" class="btn btn-primary btn-rounded btn-sm"><i class="fa fa-search"></i>&nbsp;搜索</button>
                            <button class="btn btn-warning btn-rounded btn-sm" type="reset"><i class="fa fa-eraser"></i>&nbsp;重置</button>
                            <button id="roleAdvancedSearch" type="button" class="btn btn-primary btn-rounded btn-sm" style="display: none"><i class="fa fa-caret-down"></i>&nbsp;高级搜索</button>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="col-sm-12 select-info">
            <div class="btn-group hidden-xs toolbar" id="roleToolBar" role="group">
                <a class="btn btn-outline btn-success btn-rounded" onclick="toAdd()" shiro:hasPermission="sys:role:save">
                    <i class="fa fa-plus"></i> 新增
                </a>
                <a class="btn btn-outline btn-success btn-rounded" onclick="toEdit()" shiro:hasPermission="sys:role:update">
                    <i class="fa fa-edit"></i> 编辑
                </a>
                <a class="btn btn-outline btn-danger btn-rounded" onclick="deleteRole()" shiro:hasPermission="sys:role:delete">
                    <i class="fa fa-remove"></i> 删除
                </a>
            </div>
            <table id="role">
            </table>
        </div>
    </div>
</div>
<!--引入公共js-->
<div th:include="common/onload_js :: onloadJS"></div>
<!-- Page-Level Scripts -->
<script type="text/javascript">
    var searcher = Searcher.createBS('#role',
        [
            {checkbox: true},
            {title: 'roleId',field:"roleId", visible: false},
            {title: "角色名称", field:"roleName", align: 'center', valign: 'middle'},
            {title: "所属部门",field:"deptName",  align: 'center', valign: 'middle'},
            {title: "备注",field:"remark",  align: 'center', valign: 'middle'},
            {title: "创建时间",field:"createTime",  align: 'center', valign: 'middle'}
        ]
    );

    /**
     * 跳转至新增页
     */
    function toAdd() {
        var index = Dialog.openUrl("新增", ctxPath + '/modules/sys/role/role_add.html',{area : ['900px','700px'],
            maxmin: true,
            end: function() {
                searcher.refresh()
            }
        });
        layer.full(index);
    }

    /**
     * 编辑
     */
    function toEdit() {
        var rowDatas = searcher.getSelectedRows("roleId");
        if (rowDatas.length != 1) {
            Dialog.errorMsg("请选择一行进行编辑");
            return;
        }
        var index = Dialog.openUrl("编辑", ctxPath + '/sys/role/toEdit/'+rowDatas,{area : ['900px','650px'], end: function () {
                searcher.refresh()
        }  });
        layer.full(index);
    }

    function deleteRole() {
        var rowDatas = searcher.getSelectedRows("roleId");
        if (rowDatas.length < 1) {
            Dialog.errorMsg("请至少选择一行");
            return;
        }
        Dialog.confirm('确定删除？', function(index){
            Page.ajaxPOST(ctxPath + "/sys/role/delete", {roleIds: rowDatas}, function () {
                Dialog.msg("操作成功", function () {
                    searcher.refresh()
                });
            });
        });
    }

</script>
</body>
</html>